package com.eatme.web.security.domain.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name="sys_role")
public class Role implements Serializable {

    @Id
    @Column(name = "id",nullable = false)
    private  String id;

    @Column(name = "name",nullable = false)
    private  String name;

    @Transient
    private String displayName;
    /**
     * 是否内置用户
     */
    @Transient
    private boolean builtIn;



    // @Transient
    @ManyToMany(targetEntity = Permission.class,cascade=CascadeType.ALL,fetch = FetchType.EAGER)
    @JoinTable(name = "sys_role_resource",
            joinColumns = @JoinColumn(name="role_id",referencedColumnName = "id"),
            inverseJoinColumns = @JoinColumn(name = "resource_id",referencedColumnName = "id"))
    private Set<Permission> permissions;

    // @Transient
    @ManyToMany(mappedBy = "roles")
    @JsonIgnore
    private Set<User> users =new HashSet<>();

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDisplayName() {
        return displayName;
    }

    public void setDisplayName(String displayName) {
        this.displayName = displayName;
    }

    public boolean isBuiltIn() {
        return builtIn;
    }

    public void setBuiltIn(boolean builtIn) {
        this.builtIn = builtIn;
    }

    public Set<Permission> getPermissions() {
        return permissions;
    }

    public void setPermissions(Set<Permission> permissions) {
        this.permissions = permissions;
    }

    public Set<User> getUsers() {
        return users;
    }

    public void setUsers(Set<User> users) {
        this.users = users;
    }
}

